﻿using System;
using System.IO;
using System.Text;
using ProjScan.Modules;
using UnityEngine;

namespace ProjScan.Tools
{
	// Token: 0x02000165 RID: 357
	internal class FixLog
	{
		// Token: 0x06000CBF RID: 3263 RVA: 0x00038B0C File Offset: 0x00036D0C
		public void CloseFixLog()
		{
			bool flag = this.logWriter != null;
			if (flag)
			{
				this.logWriter.Close();
				this.logWriter = null;
			}
			Application.logMessageReceived -= new Application.LogCallback(this.LogCallback);
		}

		// Token: 0x06000CC0 RID: 3264 RVA: 0x00038B50 File Offset: 0x00036D50
		public void OpenFixLog(bool enableLogCallback)
		{
			bool flag = this.logWriter != null;
			if (flag)
			{
				this.CloseFixLog();
			}
			string text = ToolsHelper.GetScanOutPut() + "/FixLog/";
			string str = "Fix_Log.Log";
			bool flag2 = !Directory.Exists(text);
			if (flag2)
			{
				Directory.CreateDirectory(text);
			}
			bool flag3 = !File.Exists(text + str);
			if (flag3)
			{
				using (File.Create(text + str))
				{
				}
			}
			this.logWriter = new StreamWriter(text + str, true, Encoding.ASCII);
			this.logWriter.AutoFlush = true;
			if (enableLogCallback)
			{
				Application.logMessageReceived += new Application.LogCallback(this.LogCallback);
			}
		}

		// Token: 0x06000CC1 RID: 3265 RVA: 0x00038C28 File Offset: 0x00036E28
		private void WriteLog(string info)
		{
			bool flag = this.logWriter == null;
			if (flag)
			{
				this.CloseFixLog();
			}
			else
			{
				this.logWriter.WriteLine(info);
			}
		}

		// Token: 0x06000CC2 RID: 3266 RVA: 0x00038C5C File Offset: 0x00036E5C
		private void LogCallback(string condition, string stackTrace, LogType logType)
		{
			bool flag = this.logWriter != null;
			if (flag)
			{
				this.logWriter.Write(DateTime.Now.ToString("yyyyMMdd HHmmss") + " : [" + logType.ToString() + "]");
				this.logWriter.WriteLine(condition);
				this.logWriter.WriteLine(stackTrace);
			}
		}

		// Token: 0x06000CC3 RID: 3267 RVA: 0x00038CD0 File Offset: 0x00036ED0
		public void LogException(FixLog.FixStage fixStage, Exception exception, string ruleName, string assetPath)
		{
			this.Log(FixLog.LogLevel.EXCEPTION, fixStage, string.Concat(new string[]
			{
				"[",
				ruleName,
				"][",
				assetPath,
				"]",
				(exception.GetType() == null) ? null : exception.GetType().ToString(),
				"\n",
				exception.Message,
				"\n",
				exception.StackTrace
			}));
		}

		// Token: 0x06000CC4 RID: 3268 RVA: 0x000067FB File Offset: 0x000049FB
		public void Log(FixLog.LogLevel logLevel, string message)
		{
			this.InternalLog(logLevel, FixLog.FixStage.Unknown, string.Empty, message);
		}

		// Token: 0x06000CC5 RID: 3269 RVA: 0x0000680D File Offset: 0x00004A0D
		public void Log(FixLog.LogLevel logLevel, FixLog.FixStage fixStage, string message)
		{
			this.InternalLog(logLevel, fixStage, string.Empty, message);
		}

		// Token: 0x06000CC6 RID: 3270 RVA: 0x0000681F File Offset: 0x00004A1F
		public void Log(FixLog.LogLevel logLevel, FixLog.FixStage fixStage, string ruleName, string message1)
		{
			this.InternalLog(logLevel, fixStage, ruleName, message1);
		}

		// Token: 0x06000CC7 RID: 3271 RVA: 0x00038D58 File Offset: 0x00036F58
		public void Log(Type fixerType, string assetInfo)
		{
			StringBuilder stringBuilder = new StringBuilder();
			string value = DateTime.Now.ToString("yyyyMMdd HHmmss");
			stringBuilder.Append(value);
			stringBuilder.Append(" : ");
			bool flag = fixerType != null;
			if (flag)
			{
				Type[] interfaces = fixerType.GetInterfaces();
				Type type = interfaces[0];
				Type[] genericArguments = type.GetGenericArguments();
				Type value2 = genericArguments[0];
				stringBuilder.Append(" ProScan Rule: [").Append(value2).Append("],");
				stringBuilder.Append(" Fixer Type:[").Append(fixerType).Append("],");
			}
			bool flag2 = assetInfo != null;
			if (flag2)
			{
				stringBuilder.Append(", (").Append(assetInfo).Append(") ");
			}
			else
			{
				stringBuilder.Append("(No Assets is Fixed)");
			}
			this.WriteLog(stringBuilder.ToString());
		}

		// Token: 0x06000CC8 RID: 3272 RVA: 0x00038E3C File Offset: 0x0003703C
		public void Log(Module module_0)
		{
			StringBuilder stringBuilder = new StringBuilder(DateTime.Now.ToString("yyyyMMdd HHmmss") + " : ");
			bool flag = module_0 > Module.Unknown;
			if (flag)
			{
				stringBuilder.Append(" [").Append(module_0.ToString()).Append("]");
			}
			stringBuilder.Append("ModuleName: ").Append(module_0.ToString());
			string info = stringBuilder.ToString();
			this.WriteLog(info);
		}

		// Token: 0x06000CC9 RID: 3273 RVA: 0x00038ECC File Offset: 0x000370CC
		private void InternalLog(FixLog.LogLevel logLevel, FixLog.FixStage fixStage, string ruleName, string message)
		{
			StringBuilder stringBuilder = new StringBuilder(DateTime.Now.ToString("yyyyMMdd HHmmss") + " : ");
			bool flag = logLevel == FixLog.LogLevel.EXCEPTION;
			if (flag)
			{
				stringBuilder.Append("[[-EXCEPTION-]]");
			}
			bool flag2 = fixStage > FixLog.FixStage.Unknown;
			if (flag2)
			{
				stringBuilder.Append(" [").Append(fixStage.ToString()).Append("]");
			}
			bool flag3 = !string.IsNullOrEmpty(ruleName);
			if (flag3)
			{
				stringBuilder.Append(" (").Append(ruleName).Append(") ");
			}
			stringBuilder.Append(message);
			string info = stringBuilder.ToString();
			this.WriteLog(info);
		}

		// Token: 0x040007C3 RID: 1987
		public static FixLog Instance = new FixLog();

		// Token: 0x040007C4 RID: 1988
		private StreamWriter logWriter;

		// Token: 0x02000166 RID: 358
		public enum FixStage
		{
			// Token: 0x040007C6 RID: 1990
			Unknown,
			// Token: 0x040007C7 RID: 1991
			f1,
			// Token: 0x040007C8 RID: 1992
			f2,
			// Token: 0x040007C9 RID: 1993
			f3,
			// Token: 0x040007CA RID: 1994
			f4,
			// Token: 0x040007CB RID: 1995
			f5,
			// Token: 0x040007CC RID: 1996
			f6
		}

		// Token: 0x02000167 RID: 359
		public enum LogLevel
		{
			// Token: 0x040007CE RID: 1998
			INFO,
			// Token: 0x040007CF RID: 1999
			EXCEPTION
		}
	}
}
